package com.ihrm.common.entity;

import lombok.Data;
import lombok.NoArgsConstructor;

/**
 * 返回结果
 *   success
 *   code
 *   message
 *   data
 */


@Data
@NoArgsConstructor
public class Result {

    private int code;  // 状态码
    private boolean success;  // 是否成功
    private String message;  // 返回信息
    private Object data;  // 返回数据

    public Result(ResultCode code) {
        this.code = code.getCode();
        this.success = code.isSuccess();
        this.message = code.getMessage();
    }

    public Result(ResultCode code, Object data) {
        this.code = code.getCode();
        this.success = code.isSuccess();
        this.message = code.getMessage();
        this.data = data;
    }

    public Result(int code, boolean success, String message) {
        this.code = code;
        this.success = success;
        this.message = message;
    }

    public static Result SUCCESS() {
        return new Result(ResultCode.SUCCESS);
    }
    public static Result SUCCESS(Object data) {
        return new Result(ResultCode.SUCCESS, data);
    }
    public static Result ERROR() {
        return new Result(ResultCode.SERVER_ERROR);
    }
//    public static Result FAIL() {
//        return new Result(ResultCode.FAIL);
//    }

}
